using System;
using System.Linq;
using Repository.Abstract;
using Service.Abstract;
using DomainModel.Entities;

namespace Service.Concrete
{
    public class BaseService<TEntity> : IBaseService<TEntity> where TEntity : class, IEntityObject, IEntityWithUser
    {
        private readonly IBaseRepository<TEntity> _repository;

        public BaseService(IBaseRepository<TEntity> repository)
        {
            _repository = repository;
        }

        public IQueryable<TEntity> GetAll()
        {
            return _repository.GetAll;
        }

        public virtual IQueryable<TEntity> GetAllByUserId(Guid userId)
        {
            return _repository.GetAll.Where(x => x.UserId == userId);
        }

        public virtual void Add(TEntity entity, Guid userId)
        {
            _repository.Add(entity, userId);
        }

        public void Save(TEntity entity, Guid userId)
        {
            _repository.Save(entity, userId);
        }

        public void Delete(TEntity entity)
        {
            _repository.Delete(entity);
        }
    }
}